package com.sekill.order.controller;


import com.seckill.system.api.RemoteTbUserService;
import com.sekill.order.entity.Order;
import com.sekill.order.mapper.OrderMapper;
import com.sekill.order.service.IOrderDetailService;
import com.sekill.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.sekill.order.entity.Order;
import com.sekill.order.entity.OrderDetail;
import com.sekill.order.service.IOrderDetailService;
import com.sekill.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gao
 * @since 2021-06-18
 */
@CrossOrigin
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService iOrderService;

        @Autowired
        private RemoteTbUserService  remoteTbUserService;

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    IOrderService orderService;

    @Autowired
    IOrderDetailService orderDetailService;

    @GetMapping("listorder")
    public Order listgoods(@RequestParam("skuId") Long skuId,@RequestParam("token") String token){
        System.out.println(token+"1111");

        Long userId = remoteTbUserService.getUserId(token);

        Order order1 = iOrderService.order(skuId,userId);
        System.out.println(userId+"**************************");

        return order1;
    }


    @GetMapping("findbyuseridandskuid")
    public boolean findbyuseridandskuid(@RequestParam("skuId") Long skuId,@RequestParam("userId") Long userId){

        int findbyuseridandskuid = iOrderService.findbyuseridandskuid(skuId, userId);
        System.out.println(findbyuseridandskuid);
        if(findbyuseridandskuid>=1){
            return false;
        }

        return  true;
    }

    @PostMapping("save")
    public Long save(@RequestBody Order order){

        int addorder = orderMapper.addorder(order);
        System.out.println(order.getOrderId());
        return order.getOrderId();
    }
}

